//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS IoTDataPlane service.
///
/// IoT data IoT data enables secure, bi-directional communication between Internet-connected things (such as sensors, actuators, embedded devices, or smart appliances) and the Amazon Web Services cloud. It implements a broker for applications and things to publish messages over HTTP (Publish) and retrieve, update, and delete shadows. A shadow is a persistent representation of your things and their state in the Amazon Web Services cloud. Find the endpoint address for actions in IoT data by running this CLI command:  aws iot describe-endpoint --endpoint-type iot:Data-ATS  The service name used by Amazon Web ServicesSignature Version 4 to sign requests is: iotdevicegateway.
public struct IoTDataPlane: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the IoTDataPlane client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - region: Region of server you want to communicate with. This will override the partition parameter.
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        region: SotoCore.Region? = nil,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: region,
            partition: region?.partition ?? partition,
            serviceName: "IoTDataPlane",
            serviceIdentifier: "data-ats.iot",
            signingName: "iotdata",
            serviceProtocol: .restjson,
            apiVersion: "2015-05-28",
            endpoint: endpoint,
            serviceEndpoints: Self.serviceEndpoints,
            variantEndpoints: Self.variantEndpoints,
            errorType: IoTDataPlaneErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }


    /// custom endpoints for regions
    static var serviceEndpoints: [String: String] {[
        "cn-north-1": "data.ats.iot.cn-north-1.amazonaws.com.cn"
    ]}


    /// FIPS and dualstack endpoints
    static var variantEndpoints: [EndpointVariantType: AWSServiceConfig.EndpointVariant] {[
        [.fips]: .init(endpoints: [
            "ca-central-1": "data.iot-fips.ca-central-1.amazonaws.com",
            "us-east-1": "data.iot-fips.us-east-1.amazonaws.com",
            "us-east-2": "data.iot-fips.us-east-2.amazonaws.com",
            "us-gov-east-1": "data.iot-fips.us-gov-east-1.amazonaws.com",
            "us-gov-west-1": "data.iot-fips.us-gov-west-1.amazonaws.com",
            "us-west-1": "data.iot-fips.us-west-1.amazonaws.com",
            "us-west-2": "data.iot-fips.us-west-2.amazonaws.com"
        ])
    ]}

    // MARK: API Calls

    /// Disconnects a connected MQTT client from Amazon Web Services IoT Core. When you disconnect a client, Amazon Web Services IoT Core closes the client's network connection and optionally cleans the session state.
    @Sendable
    @inlinable
    public func deleteConnection(_ input: DeleteConnectionRequest, logger: Logger = AWSClient.loggingDisabled) async throws {
        try await self.client.execute(
            operation: "DeleteConnection", 
            path: "/connections/{clientId}", 
            httpMethod: .DELETE, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Disconnects a connected MQTT client from Amazon Web Services IoT Core. When you disconnect a client, Amazon Web Services IoT Core closes the client's network connection and optionally cleans the session state.
    ///
    /// Parameters:
    ///   - cleanSession: Specifies whether to remove the client's session state when disconnecting. Set to TRUE to delete all session information, including subscriptions and queued messages. Set to FALSE to preserve the session state. By default, this is set to FALSE (preserves the session state).
    ///   - clientId: The unique identifier of the MQTT client to disconnect. The client ID can't start with a dollar sign ($).
    ///   - preventWillMessage: Controls if Amazon Web Services IoT Core publishes the client's Last Will and Testament (LWT) message upon disconnection. Set to TRUE to prevent publishing the LWT message. Set to FALSE to allow publishing. By default, this is set to FALSE (allows publishing the LWT message).
    ///   - logger: Logger use during operation
    @inlinable
    public func deleteConnection(
        cleanSession: Bool? = nil,
        clientId: String,
        preventWillMessage: Bool? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws {
        let input = DeleteConnectionRequest(
            cleanSession: cleanSession, 
            clientId: clientId, 
            preventWillMessage: preventWillMessage
        )
        return try await self.deleteConnection(input, logger: logger)
    }

    /// Deletes the shadow for the specified thing. Requires permission to access the DeleteThingShadow action. For more information, see DeleteThingShadow in the IoT Developer Guide.
    @Sendable
    @inlinable
    public func deleteThingShadow(_ input: DeleteThingShadowRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> DeleteThingShadowResponse {
        try await self.client.execute(
            operation: "DeleteThingShadow", 
            path: "/things/{thingName}/shadow", 
            httpMethod: .DELETE, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Deletes the shadow for the specified thing. Requires permission to access the DeleteThingShadow action. For more information, see DeleteThingShadow in the IoT Developer Guide.
    ///
    /// Parameters:
    ///   - shadowName: The name of the shadow.
    ///   - thingName: The name of the thing.
    ///   - logger: Logger use during operation
    @inlinable
    public func deleteThingShadow(
        shadowName: String? = nil,
        thingName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> DeleteThingShadowResponse {
        let input = DeleteThingShadowRequest(
            shadowName: shadowName, 
            thingName: thingName
        )
        return try await self.deleteThingShadow(input, logger: logger)
    }

    /// Gets the details of a single retained message for the specified topic. This action returns the message payload of the retained message, which can  incur messaging costs. To list only the topic names of the retained messages, call ListRetainedMessages. Requires permission to access the GetRetainedMessage action. For more information about messaging costs, see Amazon Web Services IoT Core pricing - Messaging.
    @Sendable
    @inlinable
    public func getRetainedMessage(_ input: GetRetainedMessageRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> GetRetainedMessageResponse {
        try await self.client.execute(
            operation: "GetRetainedMessage", 
            path: "/retainedMessage/{topic}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Gets the details of a single retained message for the specified topic. This action returns the message payload of the retained message, which can  incur messaging costs. To list only the topic names of the retained messages, call ListRetainedMessages. Requires permission to access the GetRetainedMessage action. For more information about messaging costs, see Amazon Web Services IoT Core pricing - Messaging.
    ///
    /// Parameters:
    ///   - topic: The topic name of the retained message to retrieve.
    ///   - logger: Logger use during operation
    @inlinable
    public func getRetainedMessage(
        topic: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetRetainedMessageResponse {
        let input = GetRetainedMessageRequest(
            topic: topic
        )
        return try await self.getRetainedMessage(input, logger: logger)
    }

    /// Gets the shadow for the specified thing. Requires permission to access the GetThingShadow action. For more information, see GetThingShadow in the IoT Developer Guide.
    @Sendable
    @inlinable
    public func getThingShadow(_ input: GetThingShadowRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> GetThingShadowResponse {
        try await self.client.execute(
            operation: "GetThingShadow", 
            path: "/things/{thingName}/shadow", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Gets the shadow for the specified thing. Requires permission to access the GetThingShadow action. For more information, see GetThingShadow in the IoT Developer Guide.
    ///
    /// Parameters:
    ///   - shadowName: The name of the shadow.
    ///   - thingName: The name of the thing.
    ///   - logger: Logger use during operation
    @inlinable
    public func getThingShadow(
        shadowName: String? = nil,
        thingName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetThingShadowResponse {
        let input = GetThingShadowRequest(
            shadowName: shadowName, 
            thingName: thingName
        )
        return try await self.getThingShadow(input, logger: logger)
    }

    /// Lists the shadows for the specified thing. Requires permission to access the ListNamedShadowsForThing action.
    @Sendable
    @inlinable
    public func listNamedShadowsForThing(_ input: ListNamedShadowsForThingRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ListNamedShadowsForThingResponse {
        try await self.client.execute(
            operation: "ListNamedShadowsForThing", 
            path: "/api/things/shadow/ListNamedShadowsForThing/{thingName}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Lists the shadows for the specified thing. Requires permission to access the ListNamedShadowsForThing action.
    ///
    /// Parameters:
    ///   - nextToken: The token to retrieve the next set of results.
    ///   - pageSize: The result page size.
    ///   - thingName: The name of the thing.
    ///   - logger: Logger use during operation
    @inlinable
    public func listNamedShadowsForThing(
        nextToken: String? = nil,
        pageSize: Int? = nil,
        thingName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListNamedShadowsForThingResponse {
        let input = ListNamedShadowsForThingRequest(
            nextToken: nextToken, 
            pageSize: pageSize, 
            thingName: thingName
        )
        return try await self.listNamedShadowsForThing(input, logger: logger)
    }

    /// Lists summary information about the retained messages stored for the account. This action returns only the topic names of the retained messages. It doesn't  return any message payloads. Although this action doesn't return a message payload, it can still incur messaging costs. To get the message payload of a retained message, call GetRetainedMessage with the topic name of the retained message. Requires permission to access the ListRetainedMessages action. For more information about messaging costs, see Amazon Web Services IoT Core pricing - Messaging.
    @Sendable
    @inlinable
    public func listRetainedMessages(_ input: ListRetainedMessagesRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ListRetainedMessagesResponse {
        try await self.client.execute(
            operation: "ListRetainedMessages", 
            path: "/retainedMessage", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Lists summary information about the retained messages stored for the account. This action returns only the topic names of the retained messages. It doesn't  return any message payloads. Although this action doesn't return a message payload, it can still incur messaging costs. To get the message payload of a retained message, call GetRetainedMessage with the topic name of the retained message. Requires permission to access the ListRetainedMessages action. For more information about messaging costs, see Amazon Web Services IoT Core pricing - Messaging.
    ///
    /// Parameters:
    ///   - maxResults: The maximum number of results to return at one time.
    ///   - nextToken: To retrieve the next set of results, the nextToken value from a previous response; otherwise null to receive the first set of results.
    ///   - logger: Logger use during operation
    @inlinable
    public func listRetainedMessages(
        maxResults: Int? = nil,
        nextToken: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListRetainedMessagesResponse {
        let input = ListRetainedMessagesRequest(
            maxResults: maxResults, 
            nextToken: nextToken
        )
        return try await self.listRetainedMessages(input, logger: logger)
    }

    /// Publishes an MQTT message. Requires permission to access the Publish action. For more information about MQTT messages, see  MQTT Protocol in the IoT Developer Guide. For more information about messaging costs, see Amazon Web Services IoT Core pricing - Messaging.
    @Sendable
    @inlinable
    public func publish(_ input: PublishRequest, logger: Logger = AWSClient.loggingDisabled) async throws {
        try await self.client.execute(
            operation: "Publish", 
            path: "/topics/{topic}", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Publishes an MQTT message. Requires permission to access the Publish action. For more information about MQTT messages, see  MQTT Protocol in the IoT Developer Guide. For more information about messaging costs, see Amazon Web Services IoT Core pricing - Messaging.
    ///
    /// Parameters:
    ///   - contentType: A UTF-8 encoded string that describes the content of the publishing message.
    ///   - correlationData: The base64-encoded binary data used by the sender of the request message to identify which request the response message is for when it's received. correlationData is an HTTP header value in the API.
    ///   - messageExpiry: A user-defined integer value that represents the message expiry interval in seconds. If absent, the message doesn't expire. For more information about the limits of messageExpiry, see Amazon Web Services IoT Core message broker and protocol limits and quotas  from the Amazon Web Services Reference Guide.
    ///   - payload: The message body. MQTT accepts text, binary, and empty (null) message payloads. Publishing an empty (null) payload with retain = true deletes the retained message identified by topic from Amazon Web Services IoT Core.
    ///   - payloadFormatIndicator: An Enum string value that indicates whether the payload is formatted as UTF-8. payloadFormatIndicator is an HTTP header value in the API.
    ///   - qos: The Quality of Service (QoS) level. The default QoS level is 0.
    ///   - responseTopic: A UTF-8 encoded string that's used as the topic name for a response message. The response topic is used to describe the topic which the receiver should publish to as part of the request-response flow. The topic must not contain wildcard characters.
    ///   - retain: A Boolean value that determines whether to set the RETAIN flag when the message is published. Setting the RETAIN flag causes the message to be retained and sent to new subscribers to the topic. Valid values: true | false  Default value: false
    ///   - topic: The name of the MQTT topic.
    ///   - userProperties: A JSON string that contains an array of JSON objects. If you don’t use Amazon Web Services SDK or CLI, you must encode the JSON string to base64 format before adding it to the HTTP header. userProperties is an HTTP header value in the API. The following example userProperties parameter is a JSON string which represents two User Properties. Note that it needs to be base64-encoded:  [{"deviceName": "alpha"}, {"deviceCnt": "45"}]
    ///   - logger: Logger use during operation
    @inlinable
    public func publish(
        contentType: String? = nil,
        correlationData: String? = nil,
        messageExpiry: Int64? = nil,
        payload: AWSHTTPBody? = nil,
        payloadFormatIndicator: PayloadFormatIndicator? = nil,
        qos: Int? = nil,
        responseTopic: String? = nil,
        retain: Bool? = nil,
        topic: String,
        userProperties: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws {
        let input = PublishRequest(
            contentType: contentType, 
            correlationData: correlationData, 
            messageExpiry: messageExpiry, 
            payload: payload, 
            payloadFormatIndicator: payloadFormatIndicator, 
            qos: qos, 
            responseTopic: responseTopic, 
            retain: retain, 
            topic: topic, 
            userProperties: userProperties
        )
        return try await self.publish(input, logger: logger)
    }

    /// Updates the shadow for the specified thing. Requires permission to access the UpdateThingShadow action. For more information, see UpdateThingShadow in the IoT Developer Guide.
    @Sendable
    @inlinable
    public func updateThingShadow(_ input: UpdateThingShadowRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> UpdateThingShadowResponse {
        try await self.client.execute(
            operation: "UpdateThingShadow", 
            path: "/things/{thingName}/shadow", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Updates the shadow for the specified thing. Requires permission to access the UpdateThingShadow action. For more information, see UpdateThingShadow in the IoT Developer Guide.
    ///
    /// Parameters:
    ///   - payload: The state information, in JSON format.
    ///   - shadowName: The name of the shadow.
    ///   - thingName: The name of the thing.
    ///   - logger: Logger use during operation
    @inlinable
    public func updateThingShadow(
        payload: AWSHTTPBody,
        shadowName: String? = nil,
        thingName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> UpdateThingShadowResponse {
        let input = UpdateThingShadowRequest(
            payload: payload, 
            shadowName: shadowName, 
            thingName: thingName
        )
        return try await self.updateThingShadow(input, logger: logger)
    }
}

extension IoTDataPlane {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: IoTDataPlane, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}

// MARK: Paginators

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension IoTDataPlane {
    /// Return PaginatorSequence for operation ``listRetainedMessages(_:logger:)``.
    ///
    /// - Parameters:
    ///   - input: Input for operation
    ///   - logger: Logger used for logging
    @inlinable
    public func listRetainedMessagesPaginator(
        _ input: ListRetainedMessagesRequest,
        logger: Logger = AWSClient.loggingDisabled
    ) -> AWSClient.PaginatorSequence<ListRetainedMessagesRequest, ListRetainedMessagesResponse> {
        return .init(
            input: input,
            command: self.listRetainedMessages,
            inputKey: \ListRetainedMessagesRequest.nextToken,
            outputKey: \ListRetainedMessagesResponse.nextToken,
            logger: logger
        )
    }
    /// Return PaginatorSequence for operation ``listRetainedMessages(_:logger:)``.
    ///
    /// - Parameters:
    ///   - maxResults: The maximum number of results to return at one time.
    ///   - logger: Logger used for logging
    @inlinable
    public func listRetainedMessagesPaginator(
        maxResults: Int? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) -> AWSClient.PaginatorSequence<ListRetainedMessagesRequest, ListRetainedMessagesResponse> {
        let input = ListRetainedMessagesRequest(
            maxResults: maxResults
        )
        return self.listRetainedMessagesPaginator(input, logger: logger)
    }
}

extension IoTDataPlane.ListRetainedMessagesRequest: AWSPaginateToken {
    @inlinable
    public func usingPaginationToken(_ token: String) -> IoTDataPlane.ListRetainedMessagesRequest {
        return .init(
            maxResults: self.maxResults,
            nextToken: token
        )
    }
}
